import React from 'react';
import { message } from 'antd';
import { getBackgroundRec } from '../service';

const useGetBgRec = props => {
    const { employId, count, onData } = props;
    const [loading, setLoading] = React.useState(false);
    const [data, setData] = React.useState([]);

    React.useEffect(() => {
        const getData = async () => {
            setLoading(true);
            const res = await getBackgroundRec({ employId });
            setLoading(false);
            if (res.code === 10000) {
                if (onData) {
                    onData(res.data);
                }
                setData(res.data);
            } else {
                message.error(res.msg);
            }
        };
        if (employId) {
            getData();
        }
    }, [employId, count]);

    return [loading, data];
};

export default useGetBgRec;
